package org.vaadin.golfscoretracker.ui.components;

import org.vaadin.appfoundation.i18n.Lang;
import org.vaadin.appfoundation.i18n.TranslationUtil;
import org.vaadin.golfscoretracker.data.Hole;

import com.vaadin.data.Item;
import com.vaadin.data.validator.IntegerValidator;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

public class HoleFieldFactory extends DefaultFieldFactory {

    private static final long serialVersionUID = -7152215061611520968L;

    @Override
    public Field createField(Item item, Object propertyId, Component uiContext) {
        TextField textField = new TextField();
        textField.setNullRepresentation("");
        textField.setCaption(TranslationUtil.getFieldTranslation(Hole.class,
                (String) propertyId));
        textField.addValidator(new IntegerValidator(Lang
                .getMessage("integer validator")));
        textField.setImmediate(true);
        return textField;
    }

}
